﻿using System;
using Gtk;
using rsapasswdgen;

//
// Source: 
// http://www.obviex.com/samples/password.aspx#
//
public partial class MainWindow: Gtk.Window
{
	string labelMessage = " Count of Character from the generated Password: ";


	public MainWindow () : base (Gtk.WindowType.Toplevel)
	{
		Build ();

		entryPasswordOutput.Changed += (sender, e) => labelGeneratedPasswordLenght.Text = labelMessage + entryPasswordOutput.Text.Length.ToString();
		buttonNewPassword.Released += ButtonNewPassword_Released;

		labelGeneratedPasswordLenght.Text = labelMessage + entryPasswordOutput.Text.Length.ToString();
	}
	void GeneratePassword()
	{
		entryPasswordOutput.Text = RandomPassword.Generate(spinbuttonPasswordMinLeght.ValueAsInt, spinbuttonPasswordMaxLenght.ValueAsInt);
		labelGeneratedPasswordLenght.Text = labelMessage + entryPasswordOutput.Text.Length.ToString();
		entryPasswordOutput.WidthRequest = entryPasswordOutput.Text.Length + 2;
	}
	void ButtonNewPassword_Released (object sender, EventArgs e)
	{
		GeneratePassword();
	}

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}
